<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <style>
        li {
            border: 1px dashed #999999;
            margin: 5px;
            line-height: 35px;
            padding-left: 5px;
            font-size: 12px;
        }

        .v-enter,
        .v-leave-to {
            opacity: 0;
            transform: translateY(80px);
        }

        .v-enter-active,
        .v-leave-active {
            transition: all .6s ease;
        }

        /* 下面的 .v-move 和 .v-leave-active 配合使用,能够实现后续的列表渐渐漂浮上来的效果 */
        .v-move{
            transition: all .6s ease;
        }
        .v-leave-active{
            width: 100%;
            position: absolute;
        }

        li:hover{
            background-color: hotpink;
            transition: all 1.4s ease;
        }
    </style>
</head>

<body>
    <div id="app">
        <div>
            <label>
                Id:
                <input type="text" v-model="id">
            </label>
            <label>
                Name:
                <input type="text" v-model="name">
            </label>
            <input type="button" value="添加" @click="add">
        </div>
        
            <!-- 在实现列表过渡的时候,如果需要过渡的元素是通过 v-for 循环渲染出来的,不能使用 transition 包裹,需要使用 transition-group -->
            <!-- 通过为 transition 设置 tag 属性,指定 transition 渲染为指定的元素,如果不指定 tag 属性,默认渲染为 span -->
            <transition-group appear tag="ul">
                <li v-for="(item,i) in list" :key="item.id" @click="del(i)">
                    {{item.id}} --- {{item.name}}
                </li>
            </transition-group>
        
    </div>
    <script>
        var vm = new Vue({
            el: '#app',
            data: {
                id: '',
                name: '',
                list: [{
                        id: 1,
                        name: '赵高'
                    },
                    {
                        id: 2,
                        name: '秦桧'
                    },
                    {
                        id: 3,
                        name: '严嵩'
                    },
                    {
                        id: 4,
                        name: '和珅'
                    }
                ]
            },
            methods: {
                add() {
                    this.list.push({
                        id: this.id,
                        name: this.name
                    })
                    this.id = this.name = ''
                },
                del(i){
                    this.list.splice(i,1)
                }
            }
        })
    </script>
</body>

</html>